#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define int long long
using pii=pair<int,int>;
#define gch getchar_unlocked
const int N=20;
int n,a[N],p[N];
void exec(){
    cin>>n;
    rep(i,1,n) cin>>a[i];
    int ans=0;
    rep(i,0,(1<<n)-1){
        int tmpans=0;
        rep(j,1,n) p[j]=(bool)(i&(1<<(j-1)));
        rep(j,1,n){
            repr(k,j-1,1){
                if(p[k]==p[j]){
                    if(a[k]==a[j]) tmpans+=a[j]; 
                    break;
                }
            }
        }
        ans=max(ans,tmpans);
    }
    cout<<ans<<endl;
}
signed main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t; cin>>t;
    while(t--) exec();
} 